﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsLive.Writer.Api;

namespace SP.LiveWriter.Publish
{
    [WriterPlugin("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "Bitly Tweeter", 
        Description = "Allows you to send a tweet with a bit.ly url tied to your account.", 
        PublisherUrl = "http://bitlytweeter.codeplex.com", 
        HasEditableOptions = true, 
        ImagePath = "thumb.ico")]
    public class PublishNotification : PublishNotificationHook
    {
        public override void OnPostPublish(IWin32Window dialogOwner, IProperties properties, IPublishingContext publishingContext, bool publish)
        {
            // If some settings don't exist, let's prompt for them.
            if (Options.Contains(Constants.SiteUrl) == false ||
                Options.Contains(Constants.SiteUsername) == false ||
                Options.Contains(Constants.SitePassword) == false ||
                Options.Contains(Constants.ListName) == false ||
                string.IsNullOrEmpty(Options[Constants.SiteUrl]) ||
                string.IsNullOrEmpty(Options[Constants.SiteUsername]) ||
                string.IsNullOrEmpty(Options[Constants.ListName]) ||
                string.IsNullOrEmpty(Options[Constants.SitePassword]))
            {
                Settings settingsDialog = new Settings(Options);
                settingsDialog.ShowDialog();
            }

            string Site = Options[Constants.SiteUrl];
            string List = Options[Constants.ListName];
            string Username = Options[Constants.SiteUsername];
            string password = Options[Constants.SitePassword];

            // Launch the tweet preview dialog, passing in the post title, the post URL, bit.ly user information and other properties
            TweetPreview previewDialog = new TweetPreview(publishingContext.PostInfo.Title, publishingContext.PostInfo.Permalink,
                bitlyUser, bitlyApi, format, Options);
            previewDialog.ShowDialog(dialogOwner);

            base.OnPostPublish(dialogOwner, properties, publishingContext, publish);
        }
    }
}
